<template>
	<view>
		支付测试
	</view>
</template>

<script>
	function getRequest() {
		var url = location.search; //获取url中"?"符后的字串  
		var theRequest = new Object();
		if (url.indexOf("?") != -1) {
			var str = url.substr(1);
			strs = str.split("&");
			for (var i = 0; i < strs.length; i++) {
				theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
			}
		}
		return theRequest;
	}
	let parameter = getRequest()
	$.ajax({
		url: 'http://server.zhongqu.net.cn/api/user/payment/v1',
		type: "post",
		headers: {
			'Content-Type': 'application/json;charset=utf8',
			'x-access-token': parameter.token
		},
		dataType: "json",
		data: JSON.stringify({
			'goodId': parameter.goodId,
			'fee': parameter.fee,
			'amount': parameter.amount,
			'totalFee': parameter.totalFee
		}),
		success: function(data) {
			let temp = document.createElement("form");
			temp.action = 'https://openapi.alipay.com/gateway.do?charset=utf-8'
			temp.method = "post";
			temp.style.display = "none";
			let params = data.data;
			let strs = params.split('&');
			for (let v of strs) {
				let arr = v.split('=');
				var opt = document.createElement("input");
				opt.name = arr[0];
				opt.value = decodeURIComponent(arr[1]);
				temp.appendChild(opt);
			}
			document.body.appendChild(temp);
			temp.submit();
		}
	});
</script>

<style>
</style>
